﻿using System;
using System.Runtime.InteropServices;

namespace FileHelper
{
    public class Program
    {
        [DllImport("kernel32.dll", EntryPoint = "LoadLibrary")]
        private static extern int LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpLibFileName);

        [DllImport("kernel32.dll", EntryPoint = "GetProcAddress")]
        private static extern IntPtr GetProcAddress(int hModule, [MarshalAs(UnmanagedType.LPStr)] string lpProcName);

        [DllImport("kernel32.dll", EntryPoint = "FreeLibrary")]
        private static extern bool FreeLibrary(int hModule);

        public delegate int MyAdd(int a, int b);

        public static int GetSum()
        {
            int hModule = LoadLibrary(@"c:\test.dll");
            if (hModule != 0)
            {
                IntPtr intPtr = GetProcAddress(hModule, "Add");
                MyAdd myadd = (MyAdd)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(MyAdd));

                int sum = myadd(10, 20);
                return sum;
            }
            return 0;
        }

        public static void Main(string[] args)
        {
            //var tree = Helper.GetFoldAll(@"F:\BaiduNetdiskDownload\001-050\007-ChonoBlack");
            //Console.WriteLine(tree);
        }
    }
}